package com.tank.dubbo.service.consumer;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/9/29
 * Time: 15:12
 * To change this template use File | Settings | File Templates.
 */
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.UnknownHostException;

public class TestForStack {
    public static void main(String[] args) {
        new TestForStack().f();
    }

    private void a() {
        Throwable t = new Throwable();
        t.fillInStackTrace();
        System.out.println(getStackTraceString(t));
    }

    private void b() {
        a();
    }

    private void c() {
        b();
    }

    private void d() {
        c();
    }

    private void e() {
        d();
    }

    private void f() {
        e();
    }

    public static String getStackTraceString(Throwable tr) {
        if (tr == null) {
            return "";
        }
        Throwable t = tr;
        while (t != null) {
            if (t instanceof UnknownHostException) {
                return "";
            }
            t = t.getCause();
        }

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        tr.printStackTrace(pw);
        return sw.toString();
    }
}
